<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script src='resources/shadow-dom.js'></script>
<script src='resources/focus-utils.js'></script>
<div id="log"></div>
<!--
This test case is based on the crbug.com/618587 reproduction case:
http://jsbin.com/bonudiwagu/1/edit?html,output
-->
<input id='i0'>
<div id='x-foo'>
  <template data-mode='open' data-delegatesFocus>
    <input id='inner-before'>
    <slot></slot>
    <input id='inner-after'>
  </template>
  <div id='nested'>
    <template data-mode='open' data-delegatesFocus>
      <input id='nested-x'>
      <slot></slot>
      <input id='nested-y'>
    </template>
    <input id='light'>
  </div>
</div>
<input id='i1'>

<script>
test(function() {
  var xFoo = document.querySelector('#x-foo');
  convertTemplatesToShadowRootsWithin(xFoo);

  var elements = [
    'i0',
    'x-foo/inner-before',
    'nested/nested-x',
    'light',
    'nested/nested-y',
    'x-foo/inner-after',
    'i1'
  ];

  assert_focus_navigation_forward(elements);
  elements.reverse();
  assert_focus_navigation_backward(elements);
}, 'Focus controller should treat each slot as a focus scope.');
</script>
